Programming Questions for Practice
Write a function to check the grade of a student based on scores in 5 different subjects.
#include <stdio.h>
#include <stdlib.h>
/*
Write a function to check the grade of a student
based on scores in 5 different subjects.
Input: Scores in 5 different subjects
(an array of 5 elements).
Output: "A" if average is greater than or equal to 80.
"B" if average is between 60 and 79.
"C" if average is between 40 and 59.
"D" if average is less than 40.
*/
char* studentGrade(int input1[]) {
int i, sum = 0, avg;
for(i = 0; i < 5; i++) {
sum = sum + input1[i];
}
avg = sum / 5;
if(avg >= 80)
return "A";
else if(avg >= 60 && avg <= 79)
return "B";
else if(avg >= 40 && avg <= 59)
return "C";
else
return "D";
}
int main()
{
int marks[] = {56, 20, 30, 35, 45};
char *grade = studentGrade(marks);
printf("\nGrade = %S\n", grade);
return 0;
}
Code not available...
Code not available...